
import sys
import _acquirepy as acquirepy

acquirepy.acquireCommonInitLibraries()
bhost = "127.0.0.1"
bport = 10000
directory = "/tmp"
commkey = ""
unencrypt = ""
reencrypt = ""
jobident = ""
instanceid = ""
timemax = 0
for i in range(len(sys.argv)):
   targ = sys.argv[i]
   if ((targ[0] == '-') and (targ[1] != '-')):
      if (targ[1] == 'n'): bhost = sys.argv[i+1]
      if (targ[1] == 'p'): bport = int(sys.argv[i+1])
      if (targ[1] == 'd'): directory = sys.argv[i+1]
      if (targ[1] == 'c'): commkey = sys.argv[i+1]
      if (targ[1] == 'u'): unencrypt = sys.argv[i+1]
      if (targ[1] == 'r'): reencrypt = sys.argv[i+1]
      if (targ[1] == 'j'): jobident = sys.argv[i+1]
      if (targ[1] == 'i'): instanceid = sys.argv[i+1]
      if (targ[1] == 't'): timemax = int(sys.argv[i+1])

if (timemax == 0):
   print "Warning: time max set to zero, resetting to 24 hours"
   timemax = 3600 * 24

acquirepy.acquireComputeInitState(bhost, bport, commkey, instanceid, "wobble", commkey, "..")
acquirepy.acquireComputeUpdateUnencryptReencryptKeys("../" + unencrypt, unencrypt, "../" + reencrypt, reencrypt, 1)
upassword = acquirepy.acquireComputeGetEncryptedPassword("../password", commkey)

blocksize = 1048576
work_datastore_info = acquirepy.acquirePythonCreateDataStore(directory, unencrypt, reencrypt, 1, blocksize)
work_datastore_name = acquirepy.acquirePythonGetDSName(work_datastore_info)
work_datastore_blockcount = acquirepy.acquirePythonGetDSBlockCount(work_datastore_info)
retcode = acquirepy.acquirePythonUploadToDataStore(work_datastore_name, directory, blocksize, unencrypt)
acquirepy.acquireCommonSetPurposeFlagsOnDataStore(work_datastore_name, 1, 0, NULL, 60 * 60 * 24, 1, upassword)

acquirepy.acquireCommonDestroyState()
acquirepy.acquireCommonDestroy()

# cp /home/benlong/repos/branches/devel/scripts/workpacket.py ./
# ln -s ../_acquirepy.so _acquirepy.so
# LD_PRELOAD=../glibc_patch.so LD_LIBRARY_PATH=.. ../python ./workpacket.py -n 127.0.0.1 -p 10000 -d /tmp/ac760b34e712b57eb4ed200461563059f2d32eb1a74068179e4989189136f72a/work  -c "1a7e46660e613bcec493cb8b2e2858b77a644c049b0992e6525bd10fadad0b40" -u "1a7e46660e613bcec493cb8b2e2858b77a644c049b0992e6525bd10fadad0b40"_inp -r "1a7e46660e613bcec493cb8b2e2858b77a644c049b0992e6525bd10fadad0b40"_out -j "568.trefoil" -i "ac760b34e712b57eb4ed200461563059f2d32eb1a74068179e4989189136f72a" -t "0"
